package com.weetop.akly.activity.work;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;

import com.blankj.utilcode.util.GsonUtils;
import com.bumptech.glide.Glide;
import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonAdapter;
import com.weetop.akly.R;
import com.weetop.akly.activity.mine.MembersHolidaysRecordActivity;
import com.weetop.akly.base.BaseFragment;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.utils.BaseUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class WorkFragment extends BaseFragment {
    @BindView(R.id.gv_data)
    GridView gvData;
    Unbinder unbinder;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    private ArrayList<String> data = new ArrayList<>();
    private CommonAdapter<String> adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getActivity(), R.layout.workfragment, null);
        unbinder = ButterKnife.bind(this, view);
        data.add("打卡");
//        data.add("补卡");
        data.add("请假");
        data.add("外出");
        data.add("外勤");
        data.add("补卡");
        data.add("假期");
        data.add("加班");

        adapter = new CommonAdapter<String>(mActivity, R.layout.item_work, data) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, String item, int position) {
                helper.setText(R.id.tv_info, item);
                ImageView iv_img = helper.getView(R.id.iv_img);
                switch (position) {
                    case 0:
                        Glide.with(mActivity).load(R.mipmap.icon_daka).into(iv_img);
                        break;
//                    case 1:
//                        Glide.with(mActivity).load(R.mipmap.icon_bu).into(iv_img);
//                        break;
                    case 1:
                        Glide.with(mActivity).load(R.mipmap.icon_qingjia).into(iv_img);
                        break;
                    case 2:
                        Glide.with(mActivity).load(R.mipmap.icon_out).into(iv_img);
                        break;
                    case 3:
                        Glide.with(mActivity).load(R.mipmap.icon_waiqin).into(iv_img);
                        break;
                    case 4:
                        Glide.with(mActivity).load(R.mipmap.icon_daka).into(iv_img);
                        break;
                    case 5:
                        Glide.with(mActivity).load(R.mipmap.icon_daka).into(iv_img);
                        break;
                    case 6:
                        Glide.with(mActivity).load(R.mipmap.icon_daka).into(iv_img);
                        break;
                }
            }
        };


        gvData.setAdapter(adapter);
        gvData.setOnItemClickListener((parent, view1, position, id) -> {
            if (BaseUtils.fastClick()) {
                switch (position) {
                    case 0:
                        BaseUtils.toActivity(mActivity, WorkDaySignActivity.class);
                        break;
//                    case 1:
//                        BaseUtils.toActivity(mActivity, WorkOutSignActivity.class);
//                        break;
                    case 1:
                        BaseUtils.toActivity(mActivity, AskForLeaveActivity.class);
                        break;
                    case 2:
                        BaseUtils.toActivity(mActivity, OutApplyActivity.class);
                        break;
                    case 3:
                        BaseUtils.toActivity(mActivity, EvectionApplyActivity.class);
                        break;
                    case 4:
                        Intent intent = new Intent();
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //注意本行的FLAG设置
                        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        BaseUtils.toActivity(getActivity(), SignOutActivity.class, intent);
                        break;
                    case 5:
                        BaseUtils.toActivity(mActivity, MembersHolidaysRecordActivity.class);
                        break;
                    case 6:
                        BaseUtils.toActivity(mActivity, WorkOverTimeActivity.class);
                        break;
                }

            }
        });

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}